package show.hkl.tools.datageneration.batchproce.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import show.hkl.tools.datageneration.batchproce.writer.Writer;

import javax.annotation.Resource;

/**
 * 基于接口SchedulingConfigurer的定时任务
 * 注解EnableScheduling：用于开启定时任务
 */
@Configuration
@EnableScheduling
public class WriterSchedulingConfiguration {
    /**
     * 启动标记
     */
    public static boolean flag = true;

    /**
     * 线程开启数量,默认为3
     */
    public static int threadNum = 3;

    @Resource
    private Writer writer;


    @Scheduled(fixedDelay = 4000)
    public void execute() {
        if (flag) {
            for (int i = 0; i < threadNum; i++) {
                new Thread(writer::generation).start();
            }
        }
    }
}
